package leeon.towthree;

import java.util.Date;

import leeon.util.PropertyLoader;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LogTxMain {
	
	public static int INTERVEL = 1000*300;
	
	private static Log logger = LogFactory.getLog(LogTxMain.class);
	
	static {
		try {
			PropertyLoader pl = PropertyLoader.newInstance("db.conf");
			LogDBHelper.DB_URL = (pl.getProperty("db.url")!=null)?pl.getProperty("db.url"):LogDBHelper.DB_URL;
			LogDBHelper.DB_DRIVER = (pl.getProperty("db.driver")!=null)?pl.getProperty("db.driver"):LogDBHelper.DB_DRIVER;
			LogDBHelper.DB_USERNAME = (pl.getProperty("db.user")!=null)?pl.getProperty("db.user"):LogDBHelper.DB_USERNAME;
			LogDBHelper.DB_PASSWORD = (pl.getProperty("db.pswd")!=null)?pl.getProperty("db.pswd"):LogDBHelper.DB_PASSWORD;
			
			LogTxMain.INTERVEL = Integer.parseInt(pl.getProperty("log.intervel", "300000"));
			
		} catch (Exception e) {
			logger.info("no db config loaded, use default db config");
		}
	}
	
	public static void main(String[] args) {
		//一直进行循环
		while (true) {
			logger.info("start fetch log :[" + new Date() + "]");
		
			try {
				LogTxtHelper h = new LogTxtHelper();
				h.executeOneTime();
				
				Thread.sleep(INTERVEL);
			} catch (Exception e) {
				logger.error("error when main while", e);
			}
		}
	}

}
